require(["config"], function() {
    require(["jquery", "load"], function($) {
        function Register(){
            this.addListener();
        }
        $.extend(Register.prototype,{
            addListener(){
                $(".click_denglu").on("click",this.registerHandler);
            },
            
            registerHandler(){
                //获取表单里的信息
                const 
                    phones = /^1[0-9]{10}$/,
                    passwords = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/,
                    phos = $(".phone").val(),
                    pass = $(".password").val(),
                    pass2 = $(".password2").val();
                
                if(phones.test(phos) && passwords.test(pass) && pass == pass2){
                    const data = $(".form-register").serialize();
                    console.log(data);
                
                $.post("http://127.0.0.1/api/register.php", data, (res)=>{
                // console.log(res)
                if(res.res_body.status === 1){
                    location = "/html/login.html";
                } else {
                    $(".register-error").show();
                }
                },"json");
            }else{
                alert("手机号1开头的11位数密码是6位到16位的数必须有数字和字母组成")
            }
                return false;
            }
        });
        new Register();
    });
});